package com.system.xingzhi.controller;

import com.system.xingzhi.model.ComponentPermission;
import com.system.xingzhi.model.ReturnData;
import com.system.xingzhi.service.ComponentPermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController("/componentPermission")
@CrossOrigin
@Api(value = "/componentPermission",tags = {"组件"},description = "组件管理")
public class ComponentPermissionController {

    @Autowired
    private ComponentPermissionService componentPermissonService;

    @PostMapping(value="/addComponentPermission")
    @ApiOperation(notes = "增加组件",value = "增加组件")
    public ReturnData addUser(@ModelAttribute ComponentPermission componentPermisson){
        return  componentPermissonService.insert(componentPermisson);
    }

    @PostMapping(value="/deleteComponentPermission")
    @ApiOperation(notes = "删除组件",value = "删除组件")
    public ReturnData deleteUser(@ApiParam(name = "componentPermissonId",value = "组件id") @RequestParam("componentPermissonId") String componentPermissonId){
        return  componentPermissonService.deleteByPrimaryKey(componentPermissonId);
    }

    @PostMapping(value="/updateComponentPermission")
    @ApiOperation(notes = "更新组件",value = "更新组件")
    public ReturnData updateUser(@ModelAttribute ComponentPermission componentPermisson){
        return  componentPermissonService.updateByPrimaryKey(componentPermisson);
    }

    @GetMapping(value="/queryComponentPermission")
    @ApiOperation(notes = "组件查询",value = "组件查询")
    public ReturnData queryUser(
            @ApiParam(name = "keyWord",value = "组件名") @RequestParam(value = "keyWord",required = false) String keyWord,
            @ApiParam(name = "componentId",value = "组件id") @RequestParam(value = "componentId",required = false) String componentId,
            @ApiParam(name = "pageNum",value = "页码") @RequestParam(value="pageNum") Integer pageNum,
            @ApiParam(name = "pageSize",value = "分页条数") @RequestParam(value="pageSize") Integer pageSize
    ){
        Map<String,String> map=new HashMap<>();
        map.put("keyWord",keyWord);
        map.put("componentId",componentId);
        return  componentPermissonService.selectByParameter(map,pageNum,pageSize);
    }
    
}
